import * as $util from '/lib/hc-util.js'

var refercontrol = {
    props: {
        definition: {
            type: Object,
            default () {
                return {};
            }
        }
    },
    watch: {
        definition: { //load the reference list when show dialog
            immediate: true,
            handler: function(nv, ov) {
                this.$set(this.definition, 'settingList', $util.hc$data$type$list);
                this.$set(this.definition, 'resultStruct', mapingdef);
                // console.warn('definition watched',this.definition)
            }
        }
    },
    template: `
    <el-form-item label="数据类型" prop='refer' :rules="[{
    				required: true,
    				message: '请选数值设置的数据类型',
    				trigger: 'blur'
    			}
    		]">
    
    <el-select style='width: 100%;' v-model="definition.refer" placeholder="请选择" @change="$emit('input', $event)" >
    	<el-option v-for="item in definition.settingList" :value='item.code' :label='item.name' :key="item.code"> </el-option>
    </el-select>
    </el-form-item>
   `
};

var inputcontrol = {
    props: {
        value: {
            type: [Number, String],
            default: null
        },
        definition: {
            type: Object,
            default () {
                return {};
            }
        }
    },
    data: function() {
        return {
            inputValue: null,
        }
    },
    created: function() {
        this.inputValue = this.value;
    },

    template: `
<el-input v-model.trim='inputValue' :type="definition.refer==='number'?'number':'text'" @input="$emit('input', $event)" placeholder='请输入'></el-input>
        `
};


var mapingdef = {
    id: 1,
    code: 'result', //root of value
    name: '用户输入数据',
    type: 'text',
    important: 1,
    variableId: 0,
};

var actionconfig = {
    code: 'ValueSetter',
    name: '数据设置',
    refer: refercontrol,
    input: inputcontrol,
    // map: mapingdef,
};

export default actionconfig;
